package com.hns.can.safety.web;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.entity.CommAccDobPoitInfoEntity;
import com.hns.can.safety.service.AccidentPointService;
import com.hns.can.safety.vo.AccidentPointParamVo;
import com.hns.frame.enumrate.MsgType;
import com.hns.frame.exception.BusinessException;
import com.hns.frame.mybatis.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 事故疑点
 */
@Controller
@RequestMapping("/accidentPoint")
public class AccidentPointController extends BaseController {

    @Autowired
    private AccidentPointService accidentPointService;

    /**
     * getAccidentPointPage(事故疑点数据分页)
     *
     * @return
     * @Exception QueryExprException
     */
    @RequestMapping("/searchAccidentPointPage")
    @ResponseBody
    public Object searchAccidentPointPage(AccidentPointParamVo entity) throws Exception {
        Pagination page;
        try {
            if (entity.getFileRdIds().length == 0) {
                entity.setFileRdIds(new String[]{""});
            }
            page = accidentPointService.getAccidentPointPage(entity);
        } catch (Exception e) {
            throw new BusinessException(MsgType.ERROR.getFlag(), e.getMessage());
        }
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }


    /**
     * getAccidentPointPage(事故疑点图表数据查询)
     *
     * @return
     * @Exception QueryExprException
     */
    @RequestMapping("/getAccidentPointChart")
    @ResponseBody
    public Object getAccidentPointChart(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<CommAccDobPoitInfoEntity> commAccDobPoitInfoList = accidentPointService.getAccidentPointChart(request);
        if (commAccDobPoitInfoList == null || commAccDobPoitInfoList.size() <= 0) {
            return this.getReturnResult();
        } else
            return this.getReturnResult(commAccDobPoitInfoList);
    }

}
